package baidu.bms.filter;


import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;


/**
 * @author sunqiyuan
 * @Classname DubboContext
 * @Description TODO
 * @Date 2020/10/15 3:29 下午
 * @Version V1.0
 */
public class DubboContext {
    private static ThreadLocal<Map<String, String>> contextThreadLocal = new ThreadLocal<>();

    public static Map<String, String> getContextMap() {
        return contextThreadLocal.get();
    }

    public static void setContextMap(Map<String, String> contextMap) {
        contextThreadLocal.set(contextMap);
    }


    public static void main(String[] args) {


        for (int i = 0; i < 5; i++) {
            final int t = i;
            new Thread(new Runnable() {
                @Override
                public void run() {
                    Map<String, String> map = DubboContext.getContextMap();
                    map.put("key" + t, "v" + t);
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(DubboContext.getContextMap());
                }
            }).start();

        }
    }
}
